package com.sos.widget.view.refresh

import com.scwang.smart.refresh.layout.SmartRefreshLayout
import com.scwang.smart.refresh.layout.api.RefreshLayout
import com.scwang.smart.refresh.layout.listener.OnRefreshLoadMoreListener

/**
 * @Description
 * @Author 梁浩文
 * @Date 2023/3/30 17:25
 */

fun SmartRefreshLayout.finishLoad(more :Boolean){
    if(more){
        this.finishLoadMore()
    }else{
        this.finishLoadMoreWithNoMoreData()
    }
}

fun SmartRefreshLayout.refreshLoadListener(refresh :(()->Unit),load :(()->Unit)){
    this.setOnRefreshLoadMoreListener(object :OnRefreshLoadMoreListener{
        override fun onRefresh(refreshLayout: RefreshLayout) {
            refreshLayout.finishRefresh(2500)
            refresh.invoke()
        }

        override fun onLoadMore(refreshLayout: RefreshLayout) {
            refreshLayout.finishLoadMore(2500)
            load.invoke()
        }
    })
}